package net.skyedu.service;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.BasGrade;
import net.skyedu.bean.BasSchool;
import net.skyedu.bean.BasSubject;
import net.skyedu.bean.BasTerm;
import net.skyedu.dao.DaoSupport;

public class Query extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public Query() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		DaoSupport ds = new DaoSupport();
		
		List<BasTerm> terli = ds.searchTerm();
		List<BasSubject> subli = ds.searchSubject();
		List<BasGrade> grali = ds.searchGrade();
		List<BasSchool> schli = ds.searchSchool();
		String test=request.getParameter("type");
		request.setAttribute("schli", schli);
		request.setAttribute("terli", terli);
		request.setAttribute("subli", subli);
		request.setAttribute("grali", grali);
		String graid=request.getParameter("graid");
		if(graid!=null)
		{
			request.setAttribute("graid", Integer.parseInt(graid));
		}
		else
		{
			request.setAttribute("graid", 0);
		}
		if(test==null||"".equals(test))
		{
		request.getRequestDispatcher("fee.jsp").forward(request, response);
		}
		else if("1".equals(test))
		{
			request.getRequestDispatcher("feeSecond.jsp").forward(request, response);
		}
		else if("2".equals(test))
		{
			request.getRequestDispatcher("feeThird.jsp").forward(request, response);
		}
	}
	

	public void init() throws ServletException {}

}
